<?php

namespace app\index\controller;

use app\model\Menu;
use app\model\Role;
use \Firebase\JWT\JWT;
use think\facade\Db;

class Index
{
    public function index()
    {

        $postData = input();

        $limit = input('limit', 10);
        $page = (input('page', 1) - 1) * $limit;

        $order = ['aid' => 'desc', 'a.addtime' => 'desc'];
        if (input('?field') && input('?order')) {
            $order = ["a." . $postData['field'] => $postData['order']];
        }


        $where['is_del'] = 1;

        $table =Db::table('jw_admin');
        if (isset($postData['query']) && !empty($postData['query'])) {
            $table->where('account|mobile', 'like', '%' . $postData['query'] . '%');
        }
        $userlist =$table
            ->alias('a')
            ->join('jw_role r ','a.role= r.rid')
            ->limit($page, $limit)
            ->field("aid,account,mobile,status,a.addtime as addtime,a.lasttime as lasttime,last_ip,a.role,name as roleName")
            ->order($order)
            ->select();

        $data['count'] = $table->count();
        $data['list'] = $userlist;

        return json($data);
    }

}